package net.aetherial.context.grounding.estimators;

import java.util.*;

import net.aetherial.context.grounding.annotators.*;

/**
 * Generates an estimated based upon the cumulative count of positive feedback or acknowledgements detected during the conversation.
 */

public class PositiveFeedbackEstimator extends Estimator
{
	private static ArrayList<String> positiveWords;
	
	static 
	{
		positiveWords = new ArrayList<String> ();
		
		positiveWords.add ("ok");
		positiveWords.add ("okay");
		positiveWords.add ("yup");
		positiveWords.add ("yes");
		positiveWords.add ("yeah");
		positiveWords.add ("got it");
	}
	
	private double count;
	
	/**
	 * @see net.aetherial.context.grounding.estimators.Estimator#reset()
	 */
	
	public void reset ()
	{
		count = 0.0;
	}
	
	/**
	 * Constructor.
	 */
	
	public PositiveFeedbackEstimator ()
	{
		count = 0.0;
	}

	/**
	 * Generates an estimate using the annotation produced by the <code>PunctuationStrippingAnnotator</code>.
	 * 
	 * @param layers	Annotated layers of the conversational unit. 
	 * @return			Count of the number of detected positive feedbacks in the current conversation. 
	 */
	
	public double estimate (Map<String, Map<String, Object>> layers)
	{
		Map<String, Object> layer = layers.get ((new PunctuationStrippingAnnotator ()).getLayerName ());

		String sender = (String) layer.get (SENDER_KEY);
		String contribution = (String) layer.get (CONTRIBUTION_KEY);
		Double score = (Double) layer.get (SCORE_KEY);

		return this.estimate (sender, contribution, score);
	}

	/**
	 * @see net.aetherial.context.grounding.estimators.Estimator#estimate(java.lang.String, java.lang.String, double)
	 */
	
	public double estimate (String sender, String contribution, double score) 
	{
		if (positiveWords.contains (contribution))
			count += 1;
		
		return count;
	}

	/**
	 * Returns "PositiveFeedbackEstimator".
	 * @see net.aetherial.context.grounding.estimators.Estimator#getName()
	 */

	public String getName() 
	{
		return "PositiveFeedbackEstimator";
	}
}
